<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>产品类型</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="description" content="产品类型">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<jsp:include page="../commons/top.jsp"/>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  <script type='text/javascript' src='/sm/dwr/interface/managerAjax.js'></script>
 <script type='text/javascript' src='/sm/dwr/engine.js'></script>
  <script>
      function del(id){
          var form = document.getElementById("listForm");
          form.id.value = id;
          form.action = "/sm/controller/typeItem/del";
          form.submit();
      }
      function add(form){

          if(isNull(form.displayName.value)){
              alert("请输入产品类型名称！");
              return false;
          }
          managerAjax.getTypeItemListByName(form.displayName.value,callBack);
      }
      
      function callBack(typeItemList){
      var form = document.getElementById('addForm');
          if(typeItemList!=null && typeItemList.length>0){
              alert("产品类型已存在，请重新输入！");
              return false;
          }else{
              form.submit();
          }
      }
      
      function mod(id){
          window.open ('/sm/controller/typeItem/getTypeItem.html?id='+id, 'newwindow', 'height=400, width=400, top=200, left=500, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no') 
      }
  </script>
  <body>
  <form id="listForm" action="/sm/controller/typeItem/" method="POST">
  <input type="hidden" name="id" value=""/>
  <table>
  <tr><td>产品类型列表</td></tr></table>
  <table>
  <tr>
      <td>序号</td>
      <td>产品类型名称</td>
      <td>父类型</td>
      <td>操作</td>
  </tr>
    <c:if test="${typeItemList!=null}">
       <c:forEach var="typeItem" items="${typeItemList}">
          <tr>
              <td><c:if test="${sessionScope.user.role == 'admin'}"><input type="radio" name="id" value="${typeItem.id}" onclick="mod('${typeItem.id}');"/></c:if>${typeItem.id} &nbsp;</td>
              <td>${typeItem.displayName}&nbsp;</td>
              <td>
              <c:forEach var="parentTypeItem" items="${typeItemList}">
              <c:if test="${typeItem.parentId == parentTypeItem.id}">
                 ${parentTypeItem.displayName }
              </c:if>
              
              </c:forEach>
              <c:if test="${typeItem.parentId == 0}">无</c:if>
              &nbsp;
              </td>
              <td><!--input type="button" value="删除" onclick="del(${typeItem.id});"/-->&nbsp;</td>
          </tr>
          
       </c:forEach>
    </c:if>
    </table>
    </form>
    <c:if test="${sessionScope.user.role == 'admin'}">
    <form id="addForm" action="/sm/controller/typeItem/add" method="POST">
    <table>
        <tr><td>添加产品类型</td></tr>
        <tr>
            <td>
                                         产品类型名称：</td>
            <td><input type="text" name="displayName" value="" maxlength="100"/>
            </td>
            </tr>
            <tr>
            <td>
                                        父类型：</td>
            <td><select name="parentId">
                                        <option value="0">无</option>
                             <c:if test="${typeItemList!=null}">
                                 <c:forEach var="typeItem" items="${typeItemList}" varStatus="status">
                                 <c:if test="${typeItem.parentId == 0}">
                                     <option value="${typeItem.id}">${typeItem.displayName}</option>
                                 </c:if>
                                 </c:forEach>
                             </c:if>            
                       </select>
            </td>

        </tr>
        <tr><td>&nbsp;</td><td><input type="button" value="提交" onclick="add(addForm);"/></td></tr>
    </table>
    </form>
    </c:if>
  </body>
</html>
